package app.netant.book.book14;

import org.jsoup.select.Elements;

import app.netant.book.base.BaseDetail;
/**
 * 
 * @author JiaJ
 *
 */
public class Book14Detail extends BaseDetail {

	public Book14Detail(String netSite) {
		super(netSite);
		this.preHref = "http://www.14book.net";
	}

	@Override
	public void analyseTitle() {
		Elements parts = this.select("div.info .left table.booktable tbody tr td h1");
		if(parts.size()>0){
			String title = parts.get(0).text();
			System.out.println("【Title】:"+title);
			this.entity.setNovelName(title);
			this.entity.setNovelFullName(title+".txt");
		}
	}

	@Override
	public void analyseTags() {
		Elements parts = this.select("div.info .left table.booktable tbody tr td table tbody tr td");
		if(parts.size()>0){
			int size = parts.size();
			if(size>9){
				size = 9;
			}
			for(int i=0;i<size;i++){
				String tags = parts.get(i).text();				
				int idx = tags.indexOf("：");
				if(idx>0){
					String tagName = tags.substring(0,idx).trim();
					String tagValue = tags.substring(idx+1).trim();
					System.out.println("【Tag】:"+tagName+"="+tagValue);
					this.entity.setTag(tagName, tagValue);
				}
				
			}
		}
	}

	@Override
	public void analyseMemo() {
		
	}

	@Override
	public void analyseHref() {
		Elements parts = this.select("div.info .left .intro #read.option a");
		for(int i=0;i<parts.size();i++){
			String text = parts.get(i).text();
			if(text.indexOf("下载")>=0){
				
				String refer = parts.get(i).attr("href");
				System.out.println("【Refer】:"+refer);
				
				this.entity.setRefer(refer);
				
				Book14Detail detail = new Book14Detail(refer);
				String href = detail.stepHref();
				System.out.println("【Href】:"+href);
				
				this.entity.setDownPath(href);
				
				break;
			}
		}
	}
	
	public String stepHref(){
		Elements parts = this.select(".main .main-z .downlink a");
		for(int i=0;i<parts.size();i++){
			String text = parts.get(i).text();
			if(text.indexOf("直接下载")>=0){
				String href = parts.get(i).attr("href");
				return href;
			}
		}
		return null;	
	}
	
	@Override
	public void analyseType() {
		
	}
	
	public static void main(String[] args) {
		Book14Detail detail = new Book14Detail("http://www.14book.net/book/100241.html");
		detail.test();
	}



}
